<?php

namespace App\Repositories;

use App\Exceptions\BasicException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use function Matrix\add;    //引入hash

class VirusThisPrizeRepository {

    /*
     * 获取boss本期奖池列表
     * @param $type
     * @return bool
     * @throws BasicException
     * */
    public function getThisPrizeList($type=3) {
        $list = app('model_virus_this_prize')
            ->select('id','gift_id','number','ratio','percent')
            ->where('type',$type)
            ->with('gift:id,name,price,picture,special')
            ->get()->toArray();
        return $list;
    }

    /*
     *新增本期奖池礼物
     * @param $param
     * @return bool
     * @throws BasicException
     * */

    public  function  addGift($param){
        $add = app('model_virus_this_prize')->create($param);
        if ($add) return $add;
        throw new BasicException(93088);
    }


        /*
     *一键添加奖池礼物
     * @param $param
     * @return bool
     * @throws BasicException
     * */

    public  function  addAllGift($param){
        $addAll = app('model_virus_this_prize')->insert($param);
        if ($addAll) return $addAll;
        throw new BasicException(93092);
    }

    /*
     *编辑本期奖池礼物
     * @param $param
     * @return bool
     * @throws BasicException
     * */
    public function  saveGift($param){
        $save = app('model_virus_this_prize')->where('id',$param['id'])->update($param);
        if ($save) return $save;
        throw new BasicException(93089);
    }

    /*
     *验证礼物是否存在
     * @param $type
     * @param $gift_id
     * @param $percent
     * @return bool
     * @throws BasicException
     * */
    public  function  verifyGift($type,$gift_id,$percent){
        $add = app('model_virus_this_prize')->where(['type'=>$type,'gift_id'=>$gift_id,'percent'=>$percent])->first();
        if ($add) throw new BasicException(50020);
    }

        /*
     *删除礼物
     * @param $arr_ids
     * @return bool
     * @throws BasicException
     * */
    public function delThisPrize($arr_ids){
        $del = app('model_virus_this_prize')->whereIn('id',$arr_ids)->delete();
        if ($del)  return $del;
        throw new BasicException(93090);
    }

    /*
    *一键修改礼物
    * @param $param
    * @return bool
    * @throws BasicException
    * */
    public  function  editAllGifts($param){
        app('model_virus_this_prize')->where('id',$param['id'])->update($param);
    }

    /*
    *删除某类型奖池
    * @param $type
    * @return bool
    * @throws BasicException
    * */
    public function  delPoolType($type){
       $del_type = app('model_virus_this_prize')->where('type',$type)->delete();
       if ($del_type) return $del_type;
        throw new BasicException(93091);
    }

}

?>